import { requestapi } from '/api/request.js'
import { wx_AppID,wx_AppSecret } from '/setting/acute.js'
import { Base64 } from 'js-base64'
/**
 * 通过login接口获取到的jscode，需要用他获取获取openid,unionid,session_key 
*/
async function porch(js_code){
	if(js_code===undefined||js_code==null||js_code.length==0){
		return false
	}
	return await requestapi('/wxLogin',{
		appid:wx_AppID,
		secret:wx_AppSecret,
		code:js_code
	},'POST')
}
/**
* 对token进行base64处理
*/
function encryptToken(){
	const { user_Token } = uni.getStorageSync('memberInfo')
	if(user_Token===undefined||user_Token==null||user_Token.length==0){
		return false
	}
	return 'Basic '+ Base64.encode(user_Token + ':')
}
/**
 * 获取列表
*/
async function select(url,data={},method='GET'){
	return await requestapi(url,data,method,{
		Authorization:encryptToken()
	})
}
export {
	porch,
	select
}